<#include "/common/layout.html"> 
<@layout>
<script type="text/javascript" src="/js/easyui/easyui_grid.js"></script>
<script type="text/javascript">
var model_name = "/goods";
var model_title="商铺商品";
var datagrid;
	$(function() {
		
		$("#category_id").combobox({
			url: '/goodsCategory/comboboxShopCategory',       
			valueField:'id',    
		    textField:'name',
		    editable:false,
		    width:150
		});	
		
		$('#shop_id').combobox({    
	    	url: '/shop/combobox',   
		    valueField:'id',    
		    textField:'name',
		    editable:false,
		    width:122,
		    onSelect:function(record){  
		    	$("#category_id").combobox({
		    		url: '/goodsCategory/comboboxShopCategory/' + record.id,    
		    		editable:false,
		    		valueField:'id',    
				    textField:'name'
	    		})
	    	}
	    });
		
		datagrid=$('#form_datagrid').datagrid({
		 	url:model_name+'/grid',
		 	columns:[[    
		        {field:'id',title:'编号',width:100,checkbox:true},
		        {field:'goods_no',title:'商品编号',width:80},
		        {field:'shopName',title:'商铺名称',width:100},
		        {field:'sgCatName',title:'商铺分类',width:80},
		        {field:'mgCatName',title:'公共分类',width:80},
		        {field:'name',title:'商品名称',width:150},
		        {field:'appRec',title:'首页推荐',width:60,
		      		formatter:function(value,row,index){
			      		if(row.appRec=='APP_INDEX'){
			      			return "<font color='red'> √ </font> [<a href='#' onclick='cancelRecommend("+row.id+",\""+row.appRec+"\")'>取消</a>]&nbsp;";
			      		}
					}
				},
				{field:'shopRec',title:'商铺推荐',width:60,
		      		formatter:function(value,row,index){
			      		if(row.shopRec=='SHOP_INDEX'){
			      			return "<font color='red'> √ </font> [<a href='#' onclick='cancelRecommend("+row.id+",\""+row.shopRec+"\")'>取消</a>]&nbsp;";
			      		}
					}
				},
		        {field:'unitName',title:'单位',width:80},
		        {field:'init_price',title:'原价(元)',width:80},
		        {field:'sale_price',title:'销售价(元)',width:80},
		        {field:'stock',title:'库存',width:50},
		        {field:'status',title:'状态',width:50,
		      		formatter:function(value,row,index){
			      		if(row.status=='IN'){
			      			return "<font color='red'>已上架</font>";
			      		}else{
			      			return "未上架";
			      		}
					}
				},
		        {field:'original',title:'产地',width:100},
		        /* {field:'summary',title:'简介',width:130}, */
		        {field:'icon',title:'图片',width:50,
		        formatter:function(value,row,index){
		        	if(value)
		        		return "<span url='"+value+"' style='cursor:pointer;color:blue;'  onmouseover='hoverShow(this);'onmouseout='$(\"#imgShow\").hide();'><img src='"+value+"'  height='30px'/></span>";
		        }},
		        {field:'created_time',title:'创建时间'}
		    ]]
		});
		
	})
	//批量上下架
	function batchOperator(status) {
		var rows = datagrid.datagrid('getSelections');
		var ids = [];
		var tipStr = "操作";
		if(status=='IN'){
			tipStr = "上架";
		}else if(status=='OUT'){
			tipStr = "下架";
		}else{
			return;
		}
		if (rows.length > 0) {
			$.messager.confirm('请确认', '您要'+tipStr+'当前所选商品？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].id);
					}
					$.ajax({
						url : model_name+"/batchOperator",
						data : {
							ids : ids.join(','),
							status : status
						},
						dataType : 'json',
						success : function(r) {
							datagrid.datagrid('load');
							datagrid.datagrid('unselectAll');
							if (r.success) {
								$.messager.show({
									msg:r.msg,
									title:'提示'
								});
								editRow = undefined;
							} else {
								$.messager.alert("操作错误",r.msg,'error');
							}
						}
					});
				}
			});
		} else {
			$.messager.alert('提示', '请选择要'+tipStr+'的商品！', 'error');
		}
	}
	
	//批量推荐
	function batchRecommend(recommendType) {
		var rows = datagrid.datagrid('getSelections');
		var ids = [];
		if (rows.length > 0) {
			$.messager.confirm('请确认', '您要推荐当前所选商品？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].id);
					}
					$.ajax({
						url : model_name+"/batchRecommend",
						data : {
							ids : ids.join(','),
							recommendType : recommendType
						},
						dataType : 'json',
						success : function(r) {
							datagrid.datagrid('load');
							datagrid.datagrid('unselectAll');
							if (r.success) {
								$.messager.show({
									msg:r.msg,
									title:'提示'
								});
								editRow = undefined;
							} else {
								$.messager.alert("操作错误",r.msg,'error');
							}
						}
					});
				}
			});
		} else {
			$.messager.alert('提示', '请选择要推荐的商品！', 'error');
		}
	}
	
	//取消推荐
	function cancelRecommend(id_,recommendType) {
		var cancel_url= model_name+"/cancelRecommend/"+id_+"-"+recommendType;
		
		$.messager.confirm('请确认', '确认操作？', function(r) {
			if (r) {
				$.ajax({
					url : cancel_url,
					dataType : 'json',
					success : function(r) {
						datagrid.datagrid('load');
						datagrid.datagrid('unselectAll');
						if (r.success) {
							$.messager.show({
								msg:r.msg,
								title:'提示'
							});
							editRow = undefined;
						} else {
							$.messager.alert("操作错误",r.msg,'error');
						}
					}
				});
			}
		});
	}
</script>
<script type="text/javascript" src="/js/easyui/easyui_grid_common.js"></script>
</head>
<body  class="easyui-layout">
<div id="imgShow"  style="position: absolute;display:none;border: 4px #ccc solid ;z-index:10;background-color:#fff;padding:5px;">
<img src="" width="150px">
</div>
<div region="north" border="false" title="搜索" collapsed="false"
		style="height: 60px; overflow:hidden;" align="left">
		<div class="tableForm datagrid-toolbar" >
		<form id="searchForm">
			<table style="height: 100%;width:auto;">
				<tr>
					<td>所属商铺</td>
					<td><input id="shop_id" name="EQ_s.id"></td> 
					<td>所属商铺分类</td>
					<td><input id="category_id" name="EQ_c.id"></td> 
					<td>商品名</td>
					<td><input type="text" name="LIKE_g.name"></td>
					<td>
					<a href="javascript:void(0);" class="easyui-linkbutton" iconCls="icon-search" onclick="_search();">查询</a>
					<a href="javascript:void(0);" class="easyui-linkbutton" onclick="cleanSearch();">取消</a>
					</td>
					<td>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="javascript:void(0);" class="easyui-linkbutton" onclick="batchOperator('IN');">批量上架</a>
					<a href="javascript:void(0);" class="easyui-linkbutton" onclick="batchOperator('OUT');">批量下架</a>
					</td>
					<td>
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<a href="javascript:void(0);" class="easyui-linkbutton" onclick="batchRecommend('APP');">首页推荐</a>
					<a href="javascript:void(0);" class="easyui-linkbutton" onclick="batchRecommend('SHOP');">商铺页推荐</a>
					</td>
				</tr>
			</table>
		</form>
		</div>
	</div>
<div region="center" border="false">
	<table  id="form_datagrid" ></table>
</div>
<div id="Dialog_"></div>
<div id="grid_toolbar">
<a href="javascript:void(0)" id="grid_toolbar_view" onclick="view();" class="easyui-linkbutton" data-options="iconCls:'icon-redo',plain:true">查看</a>
<#if hasAdd>
<a href="javascript:void(0)" id="grid_toolbar_add" onclick="add();" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">增加</a>
</#if>
<#if hasDel>
<a href="javascript:void(0)" id="grid_toolbar_del" onclick="del();"class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">删除</a>
</#if>
<#if hasEdit>
<a href="javascript:void(0)" id="grid_toolbar_edit" onclick="edit();" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">编辑</a>
</#if>
<a href="javascript:void(0)"  onclick="datagrid.datagrid('reload');" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
<a href="javascript:void(0)"  onclick="datagrid.datagrid('clearSelections');" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true">取消选中</a>
</div>
</body>

</@layout>